import http from "../../utils/http"

import {setToken} from '@/utils/token'

// 登录
export const login = (data) => {
    return async dispatch => {
        // 异步请求
        // console.log(data)
        const res = await http.post('/v1_0/authorizations', data)
        // console.log(res)
        const {data: {token}, message} = res.data
        if(message === 'OK') {
            // 登录成功
            // console.log(token)
            // 将登录拿到的token保存到本地缓存中
            // localStorage.setItem('geek-pc-token', token)
            setToken(token)
            // 将token存储到redux中
            dispatch({type: 'login/setToken', payload: token})
        }

    }
}